package com.supper.star.evaluate.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.supper.star.evaluate.dao.SystemDao;
import com.supper.star.evaluate.entity.SystemEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SystemService {

    @Autowired
    private SystemDao systemDao;

    /**
     * 分页
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    public PageInfo<System> getPage(Integer pageNo, Integer pageSize) {
        //TODO 注释掉的部分是另一种写法，最下面return 后面的是JAVA8的写法
        PageHelper.startPage(pageNo, pageSize);
        List<SystemEntity> list = systemDao.selectSystemList();
        return new PageInfo<>(list);
        // return PageHelper.startPage(pageNo, pageSize).doSelectPageInfo(() -> userMapper.selectAll());
    }

    /**
     * 添加system/更新system
     * @param  system
     * @return Boolean
     */
    public Boolean addSystem(SystemEntity system) {
        Boolean flag = true;
        if(system == null){
            flag = false;
        }else if (system.getId() == null) {
            systemDao.addSystem(system);
        } else {
            systemDao.updateByPrimaryKey(system);
        }
        return flag;
    }




    /**
     * 删除system
     * @param id
     * @return Boolean
     */
    public Boolean deleteSystem(Integer id) {
        Boolean falg = true;
        if(id != null) {
            systemDao.deleteSystem(id);
        }else {
            falg = false;
        }
        return falg;
    }
}

